package com.example.demo.Controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.Mapper.PeopleMapper;
import com.example.demo.Service.ManagerService;
import com.example.demo.Service.PeopleService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/manager")
public class Controller_2 {
    @Autowired
    ManagerService managerService;

    @Autowired
    private PeopleMapper peopleMapper;

    @RequestMapping("/logIn")
    @ResponseBody
    public String logIn(HttpServletRequest request){
        try {
            return JSON.toJSONString(managerService.selectManager(request.getParameter("peopleID")));
        }catch (Exception e){return "null";}
    };


    @RequestMapping("/justSearch")
    @ResponseBody
    public String justSearch(HttpServletRequest request){
        /**
         * @Param("id") int id,
            @Param("work") String work,
            @Param("nation") String nation,
            @Param("max") int max,
            @Param("min") int min*/
        int id = Integer.parseInt(request.getParameter("id"));
        String work = request.getParameter("work");
        String nation = request.getParameter("nation");
        int max= Integer.parseInt(request.getParameter("max"));
        int min= Integer.parseInt(request.getParameter("min"));
        System.out.println(id+work+nation+max+min);
        return JSON.toJSONString(peopleMapper.selectSomePeople(id,work,nation,max,min));
    }
}
